﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ControlPoint.ControlAPI
{
    public class ZWaveSensor : ZWaveDevice, IAction {
        private int _level;


        public ZWaveSensor(ZWaveController controller, SettingsList settings)
            : base(controller, settings) {

        
            ((ZWaveApi.Net.CommandClasses.SensorMultiLevel)this._commandClass).Changed += new EventHandler<ZWaveApi.Net.CommandClasses.Events.MultiLevelChangedEventArgs>(SensorOnChange);
        }


        private void SensorOnChange(object sender, ZWaveApi.Net.CommandClasses.Events.MultiLevelChangedEventArgs e) {
            this._level = e.Level;
            if (ChangeValue != null) {
                ChangeValue(this, "ChangeValue", new ActionValueInt(e.Level));
            }
        }

        public void RegisterAction(ActionFiredDelegate actionProcessor) {
            ChangeValue += actionProcessor;
        }

        public event ActionFiredDelegate ChangeValue;
    }
}
